﻿using FinalPointSet.Model.Model.Knowledge;
using FinalPointSet.Model.Model.MockData;
using FinalPointSet.ViewModel.Page.MainView;
using System.Windows.Controls;

namespace FinalPointSet.View.Page.MainView
{
    /// <summary>
    /// FieldMappingPage.xaml 的交互逻辑
    /// </summary>
    public partial class KnowledgePage : System.Windows.Controls.Page
    {
        public KnowledgePage()
        {
            InitializeComponent();
        }

        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (sender == null)
                return;
            ComboBox comboBox = (ComboBox)sender;
            KnowledgePoint kp = (KnowledgePoint)comboBox.DataContext;

            Language? newLanguage = null;
            Language? oldLanguage = null;
            if (e.AddedItems != null && e.AddedItems.Count > 0)
            {
                newLanguage = e.AddedItems[0] as Language;
            };
            if (e.RemovedItems != null && e.RemovedItems.Count > 0)
            {
                oldLanguage = e.RemovedItems[0] as Language;
            };
            KnowledgePageViewModel viewModel = (KnowledgePageViewModel)DataContext;
            viewModel.OnComboboxSelectionChange(kp.ID, newLanguage, oldLanguage);
        }
    }
}
